package com.syf.chatting.controller;

import com.syf.chatting.Service.UserServiceImpl;
import com.syf.chatting.domain.User;
import com.syf.chatting.utils.MyUtil;
import com.syf.chatting.vo.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by sunyf on 2017/10/10.
 */
@Controller
public class LoginController {
    private Logger logger = LoggerFactory.getLogger(LoginController.class);
    @Autowired
    private UserServiceImpl userService;

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public String login(Model model) {
        return "index";
    }

    @RequestMapping(value = "/registerUser", method = RequestMethod.POST)
    @ResponseBody
    public Result register(@RequestBody User user) {
        String r = MyUtil.vilatedUser(user);
        if (!r.equals("")) {
            return new Result(1000, r, null);
        } else {
            return userService.registerNewUser(user);
        }
    }


}
